package com.mju.model.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

public class SecurityUser implements UserDetails,Serializable{	

	/**
	 * 
	 */
	private static final long serialVersionUID = 7038934229215795793L;

	private UserInfo userInfo;
	
	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

	public SecurityUser() {
		
	}
	
	public SecurityUser(UserInfo userInfo) {
		this.userInfo=userInfo;
	}
	
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		List<SimpleGrantedAuthority> authorities = new ArrayList<>();
		authorities.add(new SimpleGrantedAuthority(
//				this.userInfo.getRole().toUpperCase())); //这个时候使用hasAuthority("ADMIN")
				"ROLE_"+this.userInfo.getRole().toUpperCase()));//这个时候使用hasRole("ADMIN")
		return authorities;
	}

	public UserInfo getUserInfo() {
		return userInfo;
	}

	@Override
	public String getPassword() {
		// TODO Auto-generated method stub
		return userInfo.getPasswd();
	}

	@Override
	public String getUsername() {
		// TODO Auto-generated method stub
		return userInfo.getStudentno();
	}

	@Override
	public String toString() {
		return "SecurityUser :" + userInfo.toString() ;
	}
	
}
